package com.market.common.handler;


import com.market.common.exception.BaseException;
import com.market.common.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ResponseResult<Object> handlerException(Exception ex) {
        log.error(ex.getMessage());
        return ResponseResult.error();
    }

    @ExceptionHandler(BaseException.class)
    public ResponseResult<Object> handlerException(BaseException ex) {
        log.error(ex.getMessage());
        return ResponseResult.error(ex.getResponseCode());
    }
}
